package com.cbb.lease.controller;

import com.cbb.lease.pojo.entity.Brand;
import com.cbb.lease.pojo.entity.CarConfig;
import com.cbb.lease.service.BrandService;
import com.gsj.common.pojo.R;
import com.gsj.common.utils.UploadUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartResolver;

import javax.annotation.Resource;
import java.io.InputStream;

/**
 * @program: clms-eighth01
 * @description: 这是一个汽车品牌 controller
 * @author: 陈斌斌
 * @create: 2021-07-24 15:12
 **/
@RestController
@RequestMapping("lease/brand")
public class BrandController {
    @Resource
    private BrandService brandService;

    @GetMapping("getCarBrand")
    @ApiOperation(value = "getCarBrand",httpMethod = "get")
    public R getAllBrand(){
        return brandService.getAllBrand();
    }


    @PostMapping("getAllBrandPage/{currentPage}/{pageSize}")
    @ApiOperation(value = "getAllBrandPage",httpMethod = "post")
    public R  getAllBrandPage(@PathVariable("currentPage")Integer currentPage,
                             @PathVariable("pageSize")Integer pageSize,
                             @RequestBody Brand brand){
        return brandService.getAllBrandPage(currentPage,pageSize,brand);
    }


    @ApiOperation(value = "delById",httpMethod = "delete")
    @DeleteMapping("delById")
    public R delById(@ApiParam(value = "主键ID")
                             Integer id){
        return brandService.delById(id);
    }

    @ApiOperation(value = "updateBrand",httpMethod = "put")
    @PutMapping("updateBrand")
    public R updateBrand(@ApiParam(value = "brand实体类")
                          @RequestBody Brand brand){
        return brandService.updateBrand(brand);
    }


    @ApiOperation(value = "addBrand",httpMethod = "post")
    @PostMapping ("addBrand")
    public R addBrand(@ApiParam(value = "brand实体类")
                     @RequestBody Brand brand){
        return brandService.addBrand(brand);
    }


    @PostMapping("upload")
    public R upload(MultipartFile file){
        try {
            InputStream inputStream = file.getInputStream();
            String filename = file.getOriginalFilename();
            String upload = UploadUtil.Upload(inputStream, filename);
            return R.ok().put("path",upload);
        }catch (Exception e){
            return R.error();
        }
    }


    @GetMapping("EC")
    public R getEC(){
        return brandService.getEC();
    }

}
